package ae.pcfc.cldos.online.common.tscdb.dao.provider;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

import ae.pcfc.cldos.online.common.dao.GenericDAO;
import ae.pcfc.cldos.online.common.tscdb.dao.TTscClientCompanyDAO;
import ae.pcfc.cldos.online.common.tscdb.domain.TTscClientCompany;

/**
 * 
 * @author arosa
 *
 */
public class TTscClientCompanyDAOImpl extends GenericDAO implements TTscClientCompanyDAO {

	public String getLicenseNumberNyTrakheesId(String trakheesId){
		DetachedCriteria criteria = DetachedCriteria.forClass(TTscClientCompany.class);
		criteria.add(Restrictions.eq(TTscClientCompany.__TRAKHEES_ID, trakheesId));
		criteria.add(Restrictions.eq(TTscClientCompany.__LIC_STATUS, "A"));
		criteria.add(Restrictions.eq(TTscClientCompany.__COMP_STATUS, "A"));
		criteria.setProjection(Projections.property(TTscClientCompany.__LICENSE_ID));
		return (String)criteria.getExecutableCriteria(getCurrentSession()).uniqueResult();
	}
	
	public TTscClientCompany getCompanyByTrakheesId(String trakheesId){
		DetachedCriteria criteria = DetachedCriteria.forClass(TTscClientCompany.class);
		criteria.add(Restrictions.eq(TTscClientCompany.__TRAKHEES_ID, trakheesId));
		criteria.add(Restrictions.eq(TTscClientCompany.__LIC_STATUS, "A"));
		criteria.add(Restrictions.eq(TTscClientCompany.__COMP_STATUS, "A"));
		return (TTscClientCompany)criteria.getExecutableCriteria(getCurrentSession()).uniqueResult();
	}
	
	public String getCompanyTrakheesIdByLicanseNo(String licenseNo){
		DetachedCriteria criteria = DetachedCriteria.forClass(TTscClientCompany.class);
		criteria.add(Restrictions.eq(TTscClientCompany.__LICENSE_ID, licenseNo));
		criteria.add(Restrictions.eq(TTscClientCompany.__LIC_STATUS, "A"));
		criteria.add(Restrictions.eq(TTscClientCompany.__COMP_STATUS, "A"));
		criteria.setProjection(Projections.property(TTscClientCompany.__TRAKHEES_ID));
		return (String)criteria.getExecutableCriteria(getCurrentSession()).uniqueResult();
	}
	
	@SuppressWarnings("unchecked")
	public List<TTscClientCompany> getAllActiveCompanies(){
		DetachedCriteria criteria = DetachedCriteria.forClass(TTscClientCompany.class);
		criteria.add(Restrictions.eq(TTscClientCompany.__LIC_STATUS, "A"));
		criteria.add(Restrictions.eq(TTscClientCompany.__COMP_STATUS, "A"));
		//criteria.add(Restrictions.ge(TTscClientCompany.__LIC_EXP_DATE, new Date()));
		return (List<TTscClientCompany>)getListByCriteria(criteria);
	}
	
}
